import  { tool }  from "../tool/index"
import { createStore } from 'vuex'
import createPersistedState from 'vuex-persistedstate'
var store = createStore({
    plugins: [createPersistedState()],
    state() {
    return {
      user:''
    }
  },
  mutations: {
    userAdd(state, user) {
      state.user = user
    },
    outUser(state){
      state.user =''
    },
    async changeUser(state,object){
      const key = Object.keys(object)
      const value =Object.values(object)
      for (let index = 0; index < key.length; index++) {
        if(state.user[`${key[index]}`] != undefined){
          state.user[`${key[index]}`] = value[index]
      }
    }
  },
    async upDate(state){
      const data = {
        params:{
          key:"Search",
          data:{
            key:["id"],
            value:[state.user.id]
          }
        }
      }
      const counts = await tool.axiosApi("user", data, "get")
      state.user = counts.data[0]
    }
  }
})

export default store